package com.aaa.book_mall.dao.impl;

import com.aaa.book_mall.dao.RoleDao;
import com.aaa.book_mall.entity.Role;
import com.aaa.book_mall.util.JDBCUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @ClassName RoleDaoImpl
 * @Description ToDo
 * @Auther teacher Bai
 * @Date 2020/12/28 9:09
 */
@Repository
public class RoleDaoImpl implements RoleDao {

    @Override
    public List<Map<String, Object>> getAllRole() {
        String sql = "select * from t_role";
        List<Map<String, Object>> maps = JDBCUtil.queryListMap(sql);
        if(maps.size()>0){
            return maps;
        }
        return null;
    }

    @Override
    public int insertRole(Role role) {
        String sql = "insert into t_role values(null,?,?,?)";
        int i = JDBCUtil.update(sql, role.getRname(), role.getMemo(), role.getStatus());
        return i;
    }

    @Override
    public int updateRole(Role role) {
        String sql = "update t_role set rname=?,memo=?,status=? where rid=?";
        int i = JDBCUtil.update(sql, role.getRname(), role.getMemo(), role.getStatus(), role.getRid());
        return i;
    }
}
